//package com.neusoft.weekreport.component.bizService.impl;
//
//
//import com.neusoft.weekreport.component.entities.SendExcelUserInfo;
//import com.neusoft.weekreport.component.req.SendMailInfo;
//import com.neusoft.weekreport.mapper.QueryUserMapper;
//import com.neusoft.weekreport.mapper.SendExcelMailMapper;
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.xssf.usermodel.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Configurable;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.activation.DataSource;
//import javax.annotation.Resource;
//import javax.mail.util.ByteArrayDataSource;
//import java.io.ByteArrayOutputStream;
//import java.text.DateFormat;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
//@Component
//@Configurable
//@EnableScheduling
//public class MailDayTaskServiceImpl {
//
//    Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Resource
//    SendMailDayBizServiceImpl sendMailDayBizService;
//
//    @Resource
//    QueryUserMapper queryUserMapper;
//
//    @Resource
//    SendExcelMailMapper sendExcelMailMapper;
//
//    @Value("${spring.mail.dayreceiver}")
//    private String dayreceiver;
//
//    @Value("${spring.mail.daycontact}")
//    private String daycontact;
//
//    @Value("${spring.url.innernet}")
//    private String innernet;
//
//    @Value("${spring.url.outernet}")
//    private String outernet;
//
//    @Value("${spring.leaderid}")
//    private String leaderid;
//
//    //每天下午四点发送填写日报工时不足的提醒邮件
//    @Scheduled(cron = "${spring.time4}")
//    public void SendTimeMail() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        String html ="<p>老师好：</p>\n" +
//                "<p style='text-indent:2em;'>今日填写的日报工时不足，请重新填写，日报系统详细地址如下：</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'>内网地址：" +innernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'> 外网地址："+ outernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送，请勿回复，谢谢！</p> ";
//        List<Map<String,String>> datatList = queryUserMapper.selectByTime();
//        if (datatList.size() == 0){
//            logger.info("所有人填写日报的工时充足");
//        }else{
//            for (Map<String,String> dataMap : datatList){
//                sendMailInfo.setMailContent(html);
//                sendMailInfo.setSendtitle("日报填写工时不足提醒");
//                logger.info("---------------------{}",dataMap.get("emailAddress"));
//                sendMailInfo.setReceiver(dataMap.get("emailAddress"));
//                sendMailInfo.setContact("");
//                sendMailDayBizService.sendMail(sendMailInfo);
//                logger.info("每天定时发送日报工时不足提醒邮件");
//            }
//        }
//    }
//
//    //每天下午四点发送没填写日报的提醒邮件
//    @Scheduled(cron = "${spring.time4}")
//    public void SendMail() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        String html ="<p>老师好：</p>\n" +
//                "<p style='text-indent:2em;'>提醒您填写今天的日报，日报系统详细地址如下：</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'>内网地址：" +innernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'> 外网地址："+ outernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送，请勿回复，谢谢！</p> ";
//        List<Map<String,String>> datatList = queryUserMapper.selectByExample();
//        if (datatList.size() == 0){
//            logger.info("所有人都已经填完");
//        }else{
//            for (Map<String,String> dataMap : datatList){
//                sendMailInfo.setMailContent(html);
//                sendMailInfo.setSendtitle("未填写日报提醒");
//                logger.info("---------------------{}",dataMap.get("emailAddress"));
//                sendMailInfo.setReceiver(dataMap.get("emailAddress"));
//                sendMailInfo.setContact("");
//                sendMailDayBizService.sendMail(sendMailInfo);
//                logger.info("每天定时发送日报通知邮件");
//            }
//        }
//    }
//
//
//
//    //每天下午四点发送审批日报提醒邮件
//    @Scheduled(cron = "${spring.time6}")
//    public void SendGroupMail() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        String html ="<p>老师好：</p>\n" +
//                "<p style='text-indent:2em;'>请审批本组员工的今日日报，日报系统详细地址如下：</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'>内网地址：" +innernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'> 外网地址："+ outernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送，请勿回复，谢谢！</p> ";
//        List<Map<String,String>> datatList = queryUserMapper.selectByGroup();
//        if (datatList.size() == 0){
//            logger.info("所有组员填写的日报都已审批");
//        }else{
//            for (Map<String,String> dataMap : datatList){
//                sendMailInfo.setMailContent(html);
//                sendMailInfo.setSendtitle("未审核日报提醒");
//                logger.info("---------------------{}",dataMap.get("emailAddress"));
//                sendMailInfo.setReceiver(dataMap.get("emailAddress"));
//                sendMailInfo.setContact("");
//                sendMailDayBizService.sendMail(sendMailInfo);
//                logger.info("每天定时发送审批提醒邮件");
//            }
//        }
//    }
//
//    //发送填写日报情况的Excel邮件
//    @Scheduled(cron = "${spring.time5}")
//    public void SendExcel() throws Exception {
//        DateFormat df1 = DateFormat.getDateInstance();
//        String fileName = "云医疗事业部-"+df1.format(new Date())+"日报.xlsx";//文件名称
//        //chaxunxinxi
//        List<SendExcelUserInfo> userInfos = sendExcelMailMapper.selectByUser();
//        for (SendExcelUserInfo userInfo : userInfos){
//            List<Map<String,String>> projbctName = sendExcelMailMapper.selectByProject(userInfo.getUserName());
//            userInfo.setProjbctName(projbctName);
//            List<Map<String,String>> workContent = sendExcelMailMapper.selectByTask(userInfo.getUserName());
//            userInfo.setWorkContent(workContent);
//            List<Map<String,String>> workHour = sendExcelMailMapper.selectByHour(userInfo.getUserName());
//            userInfo.setWorkHour(workHour);
//            List<Map<String,String>> delivbrables = sendExcelMailMapper.selectByResult(userInfo.getUserName());
//            userInfo.setDelivbrables(delivbrables);
//            List<Map<String,String>> dictValue = sendExcelMailMapper.selectByWay(userInfo.getUserName());
//            userInfo.setDictValue(dictValue);
//            String time = sendExcelMailMapper.selectByTime(userInfo.getUserName());
//            userInfo.setLaborHour(time);
//        }
//        XSSFWorkbook workbook = writeExcelInfo(userInfos);
////        FileOutputStream out = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\软件\\"+fileName);
////        workbook.write(out);
////        out.close();
//        ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        workbook.write(bos);//把excel写入到字节数组中
//        bos.close();
//        DataSource dataSource = new ByteArrayDataSource(bos.toByteArray(),"application/vnd.ms-excel");
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        String html ="<p>各位老师好：</p>\n" +
//                "<p style='text-indent:2em;'>今日的日报填写情况在附件Excel中，请各位老师查看。</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送。</p> ";
//        sendMailInfo.setMailContent(html);
//        sendMailInfo.setSendtitle("日报数据导出报表");
//        sendMailInfo.setReceiver(dayreceiver);
//        sendMailInfo.setContact(daycontact);
//        sendMailInfo.setAttachName(fileName);
//        sendMailInfo.setAttachFile(dataSource);
//        sendMailDayBizService.sendMail(sendMailInfo);
//        logger.info("每天定时发送日报Excel邮件");
//    }
//    public XSSFWorkbook writeExcelInfo(List<SendExcelUserInfo> userInfos) throws Exception {
//        XSSFWorkbook workbook = new XSSFWorkbook();//创建Excel工作簿对象
//        XSSFSheet sheet = workbook.createSheet();//在工作簿中创建工作表对象
//        DateFormat df1 = DateFormat.getDateInstance();
//        sheet.setDisplayGridlines(false);//隐藏Excel网格线,默认值为true
//        //设置列宽度
//        sheet.setColumnWidth(0,8*256);
//        sheet.setColumnWidth(1,20*256);
//        sheet.setColumnWidth(2,21*256);
//        sheet.setColumnWidth(3,20*256);
//        sheet.setColumnWidth(4,10*256);
//        sheet.setColumnWidth(5,11*256);
//        sheet.setColumnWidth(6,22*256);
//        sheet.setColumnWidth(7,40*256);
//        sheet.setColumnWidth(8,30*256);
//        sheet.setColumnWidth(9,15*256);
//        sheet.setColumnWidth(10,8*256);
//        workbook.setSheetName(0,df1.format(new Date())+"日报");//设置工作表的名称
//
//        int colNum=0;
//        //工作明细
//
//        colNum = setWeekDetailExcel( workbook, sheet,colNum ,userInfos);
//        return workbook;
//    }
//    //循环填充工作明细内容
//    public int setWeekDetailExcel(XSSFWorkbook workbook, XSSFSheet sheet, int colNum , List<SendExcelUserInfo> userInfos){
//        Row row02 = sheet.createRow(colNum);
//        row02.setHeight((short) (27 * 20));
//        Cell cell21 = row02.createCell(0);
//        cell21.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell21.setCellValue("姓名");
//        Cell cell22 = row02.createCell(1);
//        cell22.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell22.setCellValue("邮件");
//        Cell cell23 = row02.createCell(2);
//        cell23.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell23.setCellValue("二级部门");
//        Cell cell24 = row02.createCell(3);
//        cell24.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell24.setCellValue("三级部门");
//        Cell cell25 = row02.createCell(4);
//        cell25.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell25.setCellValue("直接负责人");
//        Cell cell26 = row02.createCell(5);
//        cell26.setCellStyle(setStyleWeekDetailColunm(workbook,177,160,199));
//        cell26.setCellValue("编制");
//        Cell cell28 = row02.createCell(6);
//        cell28.setCellStyle(setStyleWeekDetailColunm(workbook,255,192,0));
//        cell28.setCellValue("项目"+"\r\n"+"（没有具体项目就空着）");
//        Cell cell29 = row02.createCell(7);
//        cell29.setCellStyle(setStyleWeekDetailColunm(workbook,255,192,0));
//        cell29.setCellValue("工作内容");
//        Cell cell30 = row02.createCell(8);
//        cell30.setCellStyle(setStyleWeekDetailColunm(workbook,255,192,0));
//        cell30.setCellValue("成果物");
//        Cell cell31 = row02.createCell(9);
//        cell31.setCellStyle(setStyleWeekDetailColunm(workbook,255,192,0));
//        cell31.setCellValue("支持方式");
//        Cell cell32 = row02.createCell(10);
//        cell32.setCellStyle(setStyleWeekDetailColunm(workbook,255,192,0));
//        cell32.setCellValue("工时"+"\r\n"+"（小时）");
//        ++colNum;
//
//        //日报具体信息
//        for (SendExcelUserInfo userInfo : userInfos) {
//
//            Row row03 = sheet.createRow(colNum);
//            Cell cell33 = row03.createCell(0);
//            cell33.setCellStyle(setStyleWeekDetailContent(workbook));
//            cell33.setCellValue(userInfo.getUserName());
//
//            Cell cell34 = row03.createCell(1);
//            cell34.setCellStyle(setStyleWeekDetailContent(workbook));
//            cell34.setCellValue(userInfo.getEmailAddress());
//
//            Cell celli35 = row03.createCell(2);
//            celli35.setCellStyle(setStyleWeekDetailContent(workbook));
//            celli35.setCellValue(userInfo.getFristGroup())
//            ;
//            Cell celli36 = row03.createCell(3);
//            celli36.setCellStyle(setStyleWeekDetailContent(workbook));
//            celli36.setCellValue(userInfo.getGroupName());
//
//            Cell celli37 = row03.createCell(4);
//            celli37.setCellStyle(setStyleWeekDetailContent(workbook));
//            celli37.setCellValue(userInfo.getDescription());
//
//            Cell celli38 = row03.createCell(5);
//            celli38.setCellStyle(setStyleWeekDetailContent(workbook));
//            celli38.setCellValue(userInfo.getUserKind());
//
//            Cell celli39 = row03.createCell(6);
//            celli39.setCellStyle(setStyleDayDetailContent(workbook));
//            String b = "";
//            int bb = 1;
//            for(Map<String,String> dataMap : userInfo.getProjbctName()){
//                String a = "";
//                if(userInfo.getProjbctName().size() != bb ){
//                    if(String.valueOf(dataMap.get("projbctName")).equals("") && String.valueOf(dataMap.get("projbctName")) == "null"){
//                        a = "";
//                    }else if(!String.valueOf(dataMap.get("projbctName")).equals("") && String.valueOf(dataMap.get("projbctName")) != "null" ){
//                        a = dataMap.get("projbctName") + ";\r\n";
//                    }
//                }else{
//                    if(String.valueOf(dataMap.get("projbctName")).equals("") && String.valueOf(dataMap.get("projbctName")) == "null"){
//                        a = "";
//                    }else if(!String.valueOf(dataMap.get("projbctName")).equals("") && String.valueOf(dataMap.get("projbctName")) != "null"){
//                        a = dataMap.get("projbctName") + ";";
//                    }
//                }
//                b+=a;
//                bb++;
//            }
//            celli39.setCellValue(b);
//
//            Cell celli40 = row03.createCell(7);
//            celli40.setCellStyle(setStyleDayDetailContent(workbook));
//            String e = "";
//            int aa = 1;
//            for (Map<String,String> dataMap : userInfo.getWorkContent()){
//                String a;
//                if (userInfo.getWorkContent().size() != aa){
//                    a =  String.valueOf(aa) + "、" + dataMap.get("workContent") +";\r\n";
//                }else {
//                    a =  String.valueOf(aa) + "、" + dataMap.get("workContent") +";";
//                }
//                e+=a;
//                aa++;
//            }
//            celli40.setCellValue(e);
//
//            Cell celli41 = row03.createCell(8);
//            String c = "";
//            int cc = 1;
//            for(Map<String,String> dataMap : userInfo.getDelivbrables()){
//                String a = "";
//                if(userInfo.getDelivbrables().size() != cc ){
//                    if(String.valueOf(dataMap.get("delivbrables")).equals("") && String.valueOf(dataMap.get("delivbrables")) == "null"){
//                        a = "";
//                    }else if(!String.valueOf(dataMap.get("delivbrables")).equals("") && String.valueOf(dataMap.get("delivbrables")) != "null" ){
//                        a = String.valueOf(cc) + "、" + dataMap.get("delivbrables") + ";\r\n";
//                    }
//                }else{
//                    if(String.valueOf(dataMap.get("delivbrables")).equals("") && String.valueOf(dataMap.get("delivbrables")) == "null"){
//                        a = "";
//                    }else if(!String.valueOf(dataMap.get("delivbrables")).equals("") && String.valueOf(dataMap.get("delivbrables")) != "null"){
//                        a = String.valueOf(cc) + "、" + dataMap.get("delivbrables") + ";";
//                    }
//                }
//                c+=a;
//                cc++;
//            }
//            celli41.setCellStyle(setStyleDayDetailContent(workbook));
//            celli41.setCellValue(c);
//
//            Cell celli42 = row03.createCell(9);
//            celli42.setCellStyle(setStyleDayDetailContent(workbook));
//            String d = "";
//            int dd = 1;
//            for(Map<String,String> dataMap : userInfo.getDictValue()){
//                String a;
//                if(userInfo.getDictValue().size() != dd){
//                    a = dataMap.get("dictValue") + ";\r\n";
//                }else{
//                    a = dataMap.get("dictValue") + ";";
//                }
//                d+=a;
//                dd++;
//            }
//            celli42.setCellValue(d);
//
//            Cell celli43 = row03.createCell(10);
//            celli43.setCellStyle(setStyleDayDetailContent(workbook));
//            celli43.setCellValue(userInfo.getLaborHour());
//            ++colNum;
//        }
//        return colNum;
//    }
//
//    //设置日报明细表头样式
//    public XSSFCellStyle setStyleWeekDetailColunm(XSSFWorkbook workbook,int a,int b,int c){
//
//        //设置单元格字体
//        XSSFCellStyle cellStyle = workbook.createCellStyle();//用于设置单元格的显示样式
//
//        XSSFColor xssfColor= new XSSFColor(new java.awt.Color(a,b,c));
//        cellStyle.setFillForegroundColor(xssfColor);
//        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
//        cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
//
//        cellStyle.setBorderBottom(BorderStyle.THIN); // 下边框
//        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderLeft(BorderStyle.THIN);// 左边框
//        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderTop(BorderStyle.THIN);// 上边框
//        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderRight(BorderStyle.THIN);// 右边框
//        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
//
//        XSSFFont font = workbook.createFont();//创建字体对象
//        font.setFontHeightInPoints((short) 10);//设置字号大小
//        font.setFontName("微软雅黑");//设置字体
//        font.setBold(true);//设置粗体
//        cellStyle.setFont(font);//将字体设置添加到单元格样式中。
//
//        cellStyle.setWrapText(true);
//        return cellStyle;
//    }
//
//    //设置日报明细内容样式
//    public XSSFCellStyle setStyleWeekDetailContent(XSSFWorkbook workbook){
//        //设置单元格字体
//        XSSFCellStyle cellStyle = workbook.createCellStyle();//用于设置单元格的显示样式
//        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
//        cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
//        cellStyle.setWrapText(true);
//        cellStyle.setBorderBottom(BorderStyle.THIN); // 下边框
//        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderLeft(BorderStyle.THIN);// 左边框
//        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderTop(BorderStyle.THIN);// 上边框
//        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderRight(BorderStyle.THIN);// 右边框
//        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
//
//        XSSFFont font = workbook.createFont();//创建字体对象
//        font.setFontHeightInPoints((short) 10);//设置字号大小
//        font.setFontName("微软雅黑");//设置字体
//        cellStyle.setFont(font);//将字体设置添加到单元格样式中。
//        cellStyle.setWrapText(true);
//        return cellStyle;
//    }
//
//    //设置日报明细内容样式
//    public XSSFCellStyle setStyleDayDetailContent(XSSFWorkbook workbook){
//        //设置单元格字体
//        XSSFCellStyle cellStyle = workbook.createCellStyle();//用于设置单元格的显示样式
//        cellStyle.setVerticalAlignment(VerticalAlignment.TOP);//顶端对齐
//        cellStyle.setWrapText(true);
//        cellStyle.setBorderBottom(BorderStyle.THIN); // 下边框
//        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderLeft(BorderStyle.THIN);// 左边框
//        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderTop(BorderStyle.THIN);// 上边框
//        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
//        cellStyle.setBorderRight(BorderStyle.THIN);// 右边框
//        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
//
//        XSSFFont font = workbook.createFont();//创建字体对象
//        font.setFontHeightInPoints((short) 10);//设置字号大小
//        font.setFontName("微软雅黑");//设置字体
//        cellStyle.setFont(font);//将字体设置添加到单元格样式中。
//        cellStyle.setWrapText(true);
//        return cellStyle;
//    }
//
//}
